package cn.haona.game.simb.comm.util;

import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Timestamp;
import java.util.Random;

public class Util
{
	private static Random random;
	/**
	 * 得到时间戳
	 * 
	 * @param time
	 * @return
	 */
	public static Timestamp getTimestamp(long time)
	{
		Timestamp ts = null;
		ts = new Timestamp(time);
		return ts;
	}

	/**
	 * 从本地文件得到字符串
	 * 
	 * @param fileName
	 * @return
	 */
	public static String getStringFromLoadFile(String fileName)
	{
		byte[] arrbFile = null;
		try
		{
			InputStream is;

			is = new FileInputStream(fileName);
			int size = is.available();
			// 文件byte[]
			arrbFile = new byte[size];
			is.read(arrbFile);
			is.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		// 字符串
		String strXML = new String(arrbFile);
		return strXML;
	}
	
	/**
	 * 随机真假
	 * @return
	 */
	public static boolean randomTrueFalse()
	{
		if(random==null)
		{
			random=new Random();
		}
		
		return random.nextBoolean();
	}
}
